<?php

namespace App\Http\Controllers;

use App\Common\Sql;

class QueryNotice extends Base
{

    public function logic()
    {
        if (!isset($this->param['period'])) {
            $period = 0;
        } else {
            $period = $this->param['period'];
        }
        $data     = array();
        $cur_time = time();
        $row      = Sql::select('t_notice_info', [['status', 1]]);
        foreach ($row as $info) {
            $type = (int)$info['type'];
            if ($type == 1) {
                $begin_time = strtotime($info['begin_time']);
                if ($begin_time + $period < $cur_time || $cur_time < $begin_time) {
                    continue;
                }
            } elseif ($type == 2) {
                $begin_time = strtotime($info['begin_time']);
                $end_time  = strtotime($info['end_time']);
                $min        = (int)$info['period'];
                if ($cur_time < $begin_time || $cur_time > $end_time) {
                    continue;
                }
                $mod = ($cur_time - $begin_time) % ($min * 60);
                if ($mod > $period) {
                    continue;
                }
            } else {
                continue;
            }
            $data["message_arr"][] = $info['message'];
        }
        return $this->returnData($data);
    }

}
